﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows;
using KBManagement.DAL;
using KBManagement.BIZ;
using KBManagement.Library;

namespace KBManagement
{
    public partial class ReportDetaiPenalty : Form
    {
        KBSQLClassDataContext context;
        public ReportDetaiPenalty(IQueryable detailPenalty)
        {
            System.Data.DataTable myTable = new DataTable("myTable");
            System.Data.DataColumn column;
            System.Data.DataRow row;

            //create 3 columns
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ID";
            column.ReadOnly = true;
            column.Unique = true;

            // Add the Column to the DataColumnCollection.
            myTable.Columns.Add(column);
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "EmployeeID";
            column.ReadOnly = true;

            // Add the Column to the DataColumnCollection.
            myTable.Columns.Add(column);
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Description";
            column.ReadOnly = true;

            // Add the Column to the DataColumnCollection.
            myTable.Columns.Add(column);
            column = new DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "datetion";
            column.ReadOnly = true;

            // Add the Column to the DataColumnCollection.
            myTable.Columns.Add(column);
            context = Utils.CreateInstance().GetDBContext();
            InitializeComponent();

            ReportDocument reportDocument = new ReportDocument();
            string path = Application.StartupPath;
            path = path.Substring(0, path.LastIndexOf("bin"));
            reportDocument.Load(path + "CrystalReportDetailPenalty.rpt");

            foreach (Penalty_Detail penalty in detailPenalty)
            {
                row = myTable.NewRow();
                row["ID"] = penalty.ID;
                row["EmployeeID"] = penalty.Pay_Salary.Employee.FullName;
                row["Description"] = penalty.Penalty.Pe_Name;
                row["datetion"] = Convert.ToDateTime(penalty.PenaltyDate).ToShortDateString();
                //add the row of data to the table
                myTable.Rows.Add(row);
            }
            reportDocument.SetDataSource(myTable);
            crystalReportViewer1.ReportSource = reportDocument;
        }
    }
}
